package com.deng.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deng.entity.Usermessage;
import com.deng.service.*;
import com.deng.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
    @Autowired
    HttpServletRequest req;
    @Autowired
    PostService postService;
    @Autowired
    CommentService commentService;
    @Autowired
    UserService userService;
    @Autowired
    UsermessageService usermessageService;
    @Autowired
    UsercollectionService usercollectionService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    WebSocketService webSocketService;
    @Autowired
    SearchService searchService;
    @Autowired
    AmqpTemplate amqpTemplate;
    public Page getPage(){
        //获取当前页数，默认值为1
        int pn= ServletRequestUtils.getIntParameter(req,"pn",1);
        //获取页面大小
        int size= ServletRequestUtils.getIntParameter(req,"size",2);
        //分页信息
        Page page=new Page(pn,size);
        return page;
    }
    //从shiro获取用户的基本信息
    public AccountProfile getProfile(){
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }
    public Long getProfileId(){
        return getProfile().getId();
    }
}

